package com.qf.service.impl;

import com.qf.mapper.StuInfoMapper;
import com.qf.mapper.impl.StuInfoMapperImpl;
import com.qf.pojo.StuInfo;
import com.qf.service.LoginService;
import com.qf.until.MD5Utils;

/**
 * @author 沐辰
 * @version v1.0
 * @description:
 * @project _4.30_Exam_two
 * @Date 2024/4/30 9:31
 * @company qf
 */
public class LoginServiceImpl implements LoginService {

    private StuInfoMapper stuInfoMapper = new StuInfoMapperImpl();

    @Override
    public StuInfo login(String username, String password) {
        if (username == null) {
            return null;
        }
        if (password == null) {
            return null;
        }
        StuInfo stuInfo = stuInfoMapper.login(username);
        if (stuInfo != null) {
            if (stuInfo.getPwd().equals(MD5Utils.md5(password).substring(0,20))) {
                return stuInfo;
            }
        }
        return null;
    }

    /**
     * 密码加密测试
     * @param args
     */
    public static void main(String[] args) {
        String pwd = "adminR";
        String s = MD5Utils.md5(pwd).substring(0,20);
        System.out.println(s);
    }
}
